local HeroExcel = require("excel.hero")
local RoleExcel = require("excel.role")
local MonsterExcel = require("excel.monster")

function checkHead()
	for heroID, heroConfig in pairs(HeroExcel.hero) do
		local headID = heroConfig.head
		local configTemp = RoleExcel.head[headID]
		if configTemp == nil then
			--assert(nil, "hero ".. heroID .. " has not head config:" .. headID)
		end
	end
end

function getHeroHeadFile()
	local heroHead = {}
	local heroHeadTemp = {}
	for heroID, heroConfig in pairs(HeroExcel.hero) do
		local headID = heroConfig.head
		if heroHeadTemp[headID] == nil then
			heroHeadTemp[headID] = true
			heroHead[#heroHead + 1] = heroID
		end
	end
	
	table.sort(heroHead)
	local str = ""
	for k, v in pairs(heroHead) do
		str = str .. v .. "\n"
	end
	str2file(str, ".//heroHead.txt")
end

function getMonsterHeadFile()
	local heroHead = {}
	local heroHeadTemp = {}
	for heroID, heroConfig in pairs(MonsterExcel.monster) do
		local headID = heroConfig.head
		if heroHeadTemp[headID] == nil then
			heroHeadTemp[headID] = true
			heroHead[#heroHead + 1] = heroID
		end
	end
	
	table.sort(heroHead)
	local str = ""
	for k, v in pairs(heroHead) do
		str = str .. v .. "\n"
	end
	str2file(str, ".//monsterHead.txt")
end

function check() 
	checkHead()
	--getHeroHeadFile()
	--getMonsterHeadFile()
end


function str2file(str, filename)
	local f = io.open(filename, "wb")
	f:write(str)
	assert(io.close(f))
end

function is_file_exist(filename)
	local f = io.open(filename, "rb")
	if not f then
		return
	end
	assert(io.close(f))
	return true
end